package Hot100;

import DMSXL._2023Before.ListNode_.ListNode;

public class hasCycle {
    public static void main(String[] args) {
        int[] listA = {1};
        ListNode headA = new ListNode(listA[0]);
        ListNode preA = headA;
        for (int i = 1; i < listA.length; i++) {
            ListNode temp = new ListNode(listA[i]);
            preA.next = temp;
            preA = preA.next;
        }
        System.out.println(hasCycle(headA));
    }
    public static boolean hasCycle(ListNode head) {
        if(head == null || head.next == null)
            return false;

        ListNode fast = head.next.next,slow = head;
        while(fast != null && fast.next != null){
            if(fast == slow)
                return true;
            fast = fast.next.next;
            slow = slow.next;
        }
        return false;
    }
}
